const jwt = require('koa-jwt');
const Router = require('koa-router');
const router = new Router({ prefix: '/topics' });
const { secret } = require('../config');

const auth = jwt({ secret });
const {
  find,
  findById,
  create, update,
  checkTopicExist,
  listFollowers,
  listQuestions
} = require('../controllers/topics');

// 获取话题信息（分页）
router.get('/', find);

//新建话题
router.post('/', auth, create);

// 获取指定话题
router.get('/:id', checkTopicExist, findById);

// 修改话题
router.patch('/:id', auth, checkTopicExist, update);

// 获取关注了某个话题的 用户列表
router.get('/:id/followers', checkTopicExist, listFollowers);

// 获取某个话题下的 所有问题列表
router.get('/:id/questions', checkTopicExist, listQuestions)

module.exports = router;